//
//  NSString+Extension.m
//  Edaox
//
//  Created by cao pan on 7/10/14.
//  Copyright (c) 2014 edaox. All rights reserved.
//

#import "NSString+Extension.h"

@implementation NSString (Extension)

+ (id)stringWithDate:(NSDate*)date format:(NSString *)format {
    assert(format != nil);
    if (date == nil)
        return nil;
	NSDateFormatter* df = [[NSDateFormatter alloc] init];
	[df setDateFormat:format];
	NSString* result = [[NSString alloc] initWithFormat:@"%@", [df stringFromDate:date]];
	return result;
}


- (NSString *)urlEncoding
{
	NSString * encodeStr = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes( kCFAllocatorDefault,
                                                                                                 (CFStringRef)self,
                                                                                                 NULL,
                                                                                                 (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                                                                 kCFStringEncodingUTF8 ));
	return encodeStr;
}


- (NSString *)urlDecoding
{
	NSMutableString * decodeStr = [NSMutableString stringWithString:self];
    [decodeStr replaceOccurrencesOfString:@"+"
                               withString:@" "
                                  options:NSLiteralSearch
                                    range:NSMakeRange(0, [decodeStr length])];
    return [decodeStr stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}


@end
